#include "stdio.h"
#include "stdlib.h"

typedef int DataType;
typedef struct StackNode {
    DataType data;
    struct StackNode *next;
} StackNode, *LinkStack;

void InitStack(LinkStack *S) {
    *S = NULL;
}

int StackEmpty(LinkStack S) {
    if(S==NULL)
        return 1;
    else
        return 0;
}

int PushStack(LinkStack *S, DataType x) {
    StackNode *p = malloc(sizeof(StackNode));
    if(!p) {
        return 1;
    }
    p->data = x;
    p->next = *S;
    *S = p;
    return 0;
}

int PopStack(LinkStack *S, DataType *x) {
    StackNode *p ;
    if(StackEmpty(*S))
        return 1;
    *x = (*S)->data;
    p = *S;
    *S = (*S)->next;
    free(p);
    return 0;
}

int GetTopStack(LinkStack S, DataType *x) {
    if(StackEmpty(S))
        return 1;
    *x = S->data;
    return 0;
}























